package com.zd.lib.http.retrofit.utils;


import com.zd.lib.http.exception.ResponseException;
import com.zd.lib.http.response.BaseEntity;

import rx.Observable;
import rx.functions.Func1;


/**
 *  解析统一  json
 *  处理  data--code
 */
public class ErrorCheckerCompat<T> implements Func1<BaseEntity<T>, Observable<BaseEntity<T>>> {


          @Override
          public Observable<BaseEntity<T>> call(BaseEntity<T> data) {
              if (data==null) return Observable.error(new ResponseException(-999,"数据异常"));

              if (data.SUCCESS()) {
                  return Observable.just(data);
              } else {
                  return Observable.error(new ResponseException(data.getCode(),data.getMsg()));
              }
          }
//      }
}
